package com.hxzy.service.impl;

import com.hxzy.util.MybatisUtil;
import com.hxzy.dto.StoreTypeDTO;
import com.hxzy.entity.StoreType;
import com.hxzy.mapper.StoreTypeMapper;
import com.hxzy.service.StoreTypeServie;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/3/8 20:52
 */
public class StoreTypeServieImpl implements StoreTypeServie {
    @Override
    public int insert(StoreType type) {
        int count;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            StoreTypeMapper mapper = sqlSession.getMapper(StoreTypeMapper.class);
            count = mapper.insert(type);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int update(StoreType type) {
        int count;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            StoreTypeMapper mapper = sqlSession.getMapper(StoreTypeMapper.class);
            count = mapper.update(type);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int delete(String id) {
        int count;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            StoreTypeMapper mapper = sqlSession.getMapper(StoreTypeMapper.class);
            count = mapper.delete(id);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public StoreType findByOne(String id) {
        StoreType storeType=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            StoreTypeMapper mapper = sqlSession.getMapper(StoreTypeMapper.class);
            storeType=mapper.findByOne(id);
        }
        return storeType;
    }

    @Override
    public List<StoreType> search(StoreTypeDTO storeTypeDTO) {
        List<StoreType> list=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            StoreTypeMapper mapper = sqlSession.getMapper(StoreTypeMapper.class);
            list = mapper.search(storeTypeDTO);
        }
        return list;
    }
}
